package com.dnjn.mes.biz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dnjn.mes.biz.domain.MesResolvePlan;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 异常解决方案表 Mapper 接口
 * </p>
 *
 * @author Amber
 * @since 2023-07-26
 */
public interface MesResolvePlanMapper extends BaseMapper<MesResolvePlan> {

    List<MesResolvePlan> selectPlanList(MesResolvePlan domain);

    @Update("update mes_resolve_plan set deleted = '1' where plan_id = #{planId}")
    Long removePlanById(@Param("planId") Long planId);

    List<MesResolvePlan> selectAllPlanList(MesResolvePlan domain);

    List<MesResolvePlan> getPlanByWorkpieceId(MesResolvePlan domain);

    //@Select("select a.*,b.workpiece_name from mes_resolve_plan a left JOIN mes_workpiece b ON a.workpiece_id = b.workpiece_id where b.assembly_id = #{assemblyId} and b.workpiece_name like concat('%', #{searchKey}, '%')  ORDER BY a.ordinal")
    List<MesResolvePlan> getPlansByAssemblyId(@Param("assemblyId") Long assemblyId,@Param("searchKey") String searchKey,@Param("equipmentId") Long equipmentId);

    @Select("select a.*,b.workpiece_name from mes_resolve_plan a left JOIN mes_workpiece b ON a.workpiece_id = b.workpiece_id where a.plan_id = #{planId} and a.deleted = '0' ")
    MesResolvePlan getPlan(@Param("planId") Long planId);
    @Select("select * from mes_resolve_plan where workpiece_id = #{workpieceId} and equipment_id=#{equipmentId} and deleted = '0' ")
    List<MesResolvePlan> getPlanPageByWorkpieceId(@Param("workpieceId") Long workpieceId,@Param("equipmentId") Long equipmentId);

    @Select("SELECT MAX(ordinal) FROM mes_resolve_plan")
    Integer getMaxOrdinal();

}
